<?
include("session.php");
$date_start = date("Y-m-d")." 00:00:00";
$date_end = date("Y-m-d")." 23:59:59";
$yesterday_start = date("Y-m-d", strtotime("-1 day"))." 00:00:00";
$yesterday_end = date("Y-m-d", strtotime("-1 day"))." 23:59:59";
$current_month_start = date("Y-m-01")." 00:00:00";
$current_month_end = date("Y-m-t")." 23:59:59";
$recent_7_days_start = date("Y-m-d", strtotime("-7 day"))." 00:00:00";
$recent_7_days_end = date("Y-m-d")." 23:59:59";
$current_week_start = date("Y-m-d", strtotime('last monday'))." 00:00:00";
$current_week_end = date("Y-m-d")." 23:59:59";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>电销助手外呼</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../../../webkit/grid/import.js"></script>
<script type="text/javascript" src="../../../webkit/dialog/import.js"></script>
<script type="text/javascript" src="../../../webkit/datepicker/WdatePicker.js"></script>
</head>
<body bgccolor="#f4f4f4" style="margin:0px;overflow-x:hidden">

<table width=100% height=100% cellspacing=0 cellpadding=0>
	<tr bgcolor="white">
	<form name=f>
	<td height=30>&nbsp;
	任务：<select id="task_id" class='input'><option value=''>-请选择-</option></select>　
	分组：<select id="agent_group" class='input'><option value=''>-请选择-</option></select>　
	时间：<input type="text" id="date_start" name="date_start" onClick="WdatePicker({readOnly:true, skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="16" value="<?echo $date_start?>"> - <input type="text" id="date_end" name="date_end" onClick="WdatePicker({readOnly:true, skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="16" value="<?echo $date_end?>">　<a href="javascript:set_date_range('<?echo $date_start?>', '<?echo $date_end?>')">本日</a> <a href="javascript:set_date_range('<?echo $yesterday_start?>', '<?echo $yesterday_end?>')">昨天</a> <a href="javascript:set_date_range('<?echo $current_week_start?>', '<?echo $current_week_end?>')">本周</a> <a href="javascript:set_date_range('<?echo $current_month_start?>', '<?echo $current_month_end?>')">本月</a>　
	<input type="button" value="查询" onclick="search()"><input type="button" value="结果图" onclick="show_chart('result')"><input type="button" value="时段图"  onclick="show_chart('datetime')">
	</td>
	</tr>
	<tr>
	<td>
		<table id="flex1" style="display:none"></table>
	</td>
	</form>
	</tr>
</table>
<iframe name="free" width=1 height=0></iframe>
<form name="dl_voice_form" method=post target="free"><input type="hidden" name="recordIds"></form>

<script>
	var agent_id = "<?echo $_GET['agent_id']?>";
	var h = window.screen.height-410; // 属于嵌入外部url，只能按screen高度大致计算
	//alert(h)
	if(h < 0) h = 'auto'
	$("#flex1").flexigrid({
		//url: 'report_query.php?action=get_task_agent_report', // 默认只显示未呼的记录
		dataType: 'json',
		colModel : [
			{display: '座席名称', name : 'a', width : 70, sortable : false, align: 'center'},
			{display: '座席工号', name : 'a', width : 70, sortable : false, align: 'center'},
			{display: '呼叫总数', name : 'call_cnt', width : 50, sortable : true, align: 'center'},
			{display: '营销成功', name : 'cnt_1', width : 50, sortable : true, align: 'center'},
			{display: '成功率', name : 'cnt_0', width : 50, sortable : true, align: 'center'},
			{display: '营销失败', name : 'cnt_2', width : 50, sortable : true, align: 'center'},
			{display: '预约回拔', name : 'cnt_3', width : 50, sortable : true, align: 'center'},
			{display: '集团彩铃', name : 'cnt_4', width : 50, sortable : true, align: 'center'},
			{display: '忙音', name : 'cnt_5', width : 50, sortable : true, align: 'center'},
			{display: '空号', name : 'cnt_6', width : 50, sortable : true, align: 'center'},
			{display: '停机', name : 'cnt_7', width : 50, sortable : true, align: 'center'},
			{display: '无人接听', name : 'cnt_8', width : 50, sortable : true, align: 'center'},
			{display: '直接挂机', name : 'cnt_9', width : 50, sortable : true, align: 'center'},
			{display: '非负责人', name : 'cnt_10', width : 50, sortable : true, align: 'center'},
			{display: '沟通障碍', name : 'cnt_11', width : 50, sortable : true, align: 'center'},
			{display: '无效数据', name : 'cnt_11', width : 50, sortable : true, align: 'center'}
			],
		async : true,
		usepager: true,
		title: '座席外呼统计',
		useRp: true,
		rp: 50,
		showTableToggleBtn: false,
		width: 'auto',
		height: h,
		resizable : false,
		singleSelect : true,
		onSuccess : function() {show_sum_total("2,3,5,6,7,8,9,10,11,12,13,14,15,")}
	});


	function set_date_range(a, b) {
		$('#date_start').val(a);
		$('#date_end').val(b);
	}


	function search() { 
		var params = get_search_params();
		if(params != "") {
			var url = "report_query.php?action=get_task_agent_report" + params;
			$('#flex1').flexOptions({'url': url}).flexReload(); 
		}
	}

	var dlg = null;
	function show_chart(type) { 
		var params = get_search_params();
		if(params != "") {
			var url = "report_panel_"+type+".php?show=1" + params;
			dlg = new Dialog({ title: '图形报表统计', resizable:false, maximizable:false}).href(url);
			dlg.show().setSize(800, 400).center();
		}
	}


	function get_search_params() {
		var params = "";
		if($("#task_id").val()!="") {
            params += "&task_id="+ $("#task_id").val();
        } 
		// 关闭选择任务的限制; 2014/10/28
		/*else {
			alert("请选择指定任务进行查询！");	
			return "";
		}*/
		if($("#agent_group").val()!="") {
            params += "&agent_group="+ encodeURI($("#agent_group").val());
        } 
	    if($("#date_start").val()!="" && $("#date_end").val()!="") {
            params += "&date_range="+ $("#date_start").val()+"_"+$("#date_end").val();
        } else {
			alert("请选择指定时间段进行查询！");	
			return "";
		}
		return params;
	}

	$(function(){
		$.get("task_query.php?action=get_select_options", function(data) {
			var arr = data.split("$");
			for(var i=0; i<arr.length; i++){
				var kv = arr[i].split(',');
				f.task_id.options[i+1] = new Option(kv[1], kv[0]);
			}
		});

		$.get("agent_query.php?action=get_group_options", function(data) {
			var arr = data.split("$");
			for(var i=0; i<arr.length; i++){
				var kv = arr[i].split(',');
				f.agent_group.options[i+1] = new Option(kv[0], kv[0]);
			}
		});
	});

</script>
</body>
</html>